package com.yhl.file;


import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.BaseFont;
import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.poifs.crypt.EncryptionMode;
import org.apache.poi.poifs.crypt.Encryptor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.springframework.stereotype.Service;


/**
 * @author: yanghl
 * @description: TODO
 * @date: 2024/7/2 17:12
 */
@Service
public class PdfFileServices {

    public void generateForLeavePdf(String fileName, String name, String date) {
        String content = "尊敬的领导：\n\n" +
                "您好！\n\n" +
                "本人 " + name + " 因个人原因，需请假一天，特此申请。\n\n" +
                "请假日期：" + date + "\n\n" +
                "望批准！\n\n" +
                "此致\n\n" +
                "敬礼\n\n" +
                "申请人：" + name + "\n\n" +
                "日期：" + date;

        com.itextpdf.text.Document document = new Document();
        try {
            PdfWriter.getInstance(document, new FileOutputStream(fileName));
            document.open();
            // 设置中文字体
            BaseFont bf = BaseFont.createFont("BodoniFLF-Roman", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            com.itextpdf.text.Font font = new com.itextpdf.text.Font(bf, 12);

            document.add(new Paragraph(content, font));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            document.close();

        }
    }
}

